// 使用节点宽高按照 实际分辨率/设计分辨率 中最大的值进行缩放

import { menu } from '../../../app/decorator';

const { ccclass } = cc._decorator;

@ccclass
@menu(__filename, '动态缩放')
export default class NodeScale extends cc.Component {
    private onResized() {
        // 设计分辨率
        let drSize = cc.view.getDesignResolutionSize();
        // 实际分辨率
        let winSize = cc.winSize;

        let scaleX = winSize.width / drSize.width;
        let scaleY = winSize.height / drSize.height;
        let scale = Math.max(scaleX, scaleY);
        this.node.scale = scale;
    }

    protected onLoad() {
        cc.view.on('canvas-resize', this.onResized, this);
        this.onResized();
    }

    protected onDestroy(): void {
        cc.view.off('canvas-resize', this.onResized, this);
    }
}